



from pyquery  import PyQuery as pq


# html = """

# <li class="bbb"> <a href="http://www.baidu.com">百度<\a><\li>

# """



# p = pq(html)

# print(p)
# print(type(p))

# a = p("a")
# print(a)
# print(type(a))

# lia = p("li")("a")
# print(lia)
# print(type(lia))

# ahoutai = p("li a") #后代选择器
# print(ahoutai)




html2 = """
        <ul>
        <li class="aaa"> <a href="http://www.google.com">谷歌</a> </li>
        <li class="aaa"> <a href="http://www.baidu.com">百度</a> </li>
        <li class="bbb" id='qq'> <a href="http://www.tencent.com">QQ</a> </li>
        <li class="bbb"> <a href="http://www.wenjia.com">文莱</a> </li>
        </ul>
        """
p2 = pq(html2)

a = p2(".aaa a")
b = p2("#qq")

print(a,"\n",b)

print("HH",p2("#qq a").attr("href"),"text=",p2("#qq a").text()) # 找属性  和 text

href = p2("li a").attr("href")  #多个标签那属性 默认拿第一个
print(href)

it = p2("li a").items()  #拿到迭代器
for item in it:
    print("item=",item)
    hrefi = item.attr("href")
    text = item.text()
    print(hrefi,text)


html3 = """
<div><span>我爱你</span></div>
"""
p3 = pq(html3)
div = p3("span").html()
span = p3("span").text()
print("p3输出div = ", div,"span=",span)
div1 = p3("div").html()
span1 = p3("div").text()
print("p3输出div1 = ", div1,"span1=",span1)




